<template>
  <div class="WorkingSchedule" v-loading="loading">
    <el-form ref="form" :model="form" label-position="top" class="myform">
      <div>
        <!-- <el-form-item label="前/后台" class="myform-item">
          <el-select v-model="form.type" placeholder="请选择" clearable>
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item label="模块名称" class="myform-item">
          <el-input
            v-model="form.name"
            placeholder="请输入模块名称"
            @keyup.enter.native="onSearch"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="模块状态" class="myform-item">
          <el-select v-model="form.status" placeholder="请选择" clearable>
            <el-option
              v-for="item in optionsTwo"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </div>
      <div>
        <el-form-item style="margin-top: 50px">
          <el-button type="primary" @click="onSearch">查询</el-button>
          <el-button type="primary" plain @click="onAddModel"
            >新增模块</el-button
          >
          <!-- <el-button type="primary">上传文件</el-button> -->
        </el-form-item>
      </div>
    </el-form>
    <el-table :data="tableData" style="width: 100%" border>
      <el-table-column label="前/后台" align="center" prop="type">
        <template slot-scope="{ row }">{{
          row.type == 0 ? "后台" : row.type == 1 ? "小程序端" : row.type == 2 ? "客户端" :row.type == 3 ? "工厂小程序" : row.type == 4 ? "工厂客户端" : ""
        }}</template>
      </el-table-column>
      <el-table-column label="标识" align="center" prop="unique">
      </el-table-column>
      <el-table-column label="模块名称" align="center" prop="name">
      </el-table-column>
      <el-table-column label="描述" align="center" prop="description">
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="{ row }">{{
          row.status == 0 ? "启用" : "禁用"
        }}</template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createtime">
      </el-table-column>
      <el-table-column label="创建者" align="center" prop="createuser">
      </el-table-column>
      <el-table-column label="icon" align="center" prop="icon">
        <template slot-scope="{ row }">
          <el-image
            :src="row.icon"
            v-if="row.icon"
            fit="contain"
            style="width: 40px; height: 40px"
          ></el-image>
        </template>
      </el-table-column>
      <el-table-column label="鼠标移入时icon" align="center" prop="mouse_icon">
        <template slot-scope="{ row }">
          <el-image
            :src="row.mouse_icon"
            v-if="row.mouse_icon"
            fit="contain"
            style="width: 40px; height: 40px"
          ></el-image>
        </template>
      </el-table-column>
      <el-table-column label="排序" align="center" prop="listorder">
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="{ row }">
          <!-- <el-button type="text" @click="onLook(row.id)">查看</el-button> -->
          <el-button type="text" @click="onEdit(row.id)">编辑</el-button>
          <el-button type="text" @click="onDelete(row.id)" style="color: red"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      :form="form"
      :total="total"
      @paginationPostOrderTaskList="postAdminUserCompetencelisttop"
    />
  </div>
</template>

<script>
import {
  postAdminUserCompetencelisttop,
  postAdminUserDelcompetence,
} from "@/api";
import pagination from "@/components/pagination.vue";
export default {
  components: { pagination },
  data() {
    return {
      loading: false,
      form: {
        type: 0,
        status: "",
        name: "",
        is_top:1,
        page: 1,
        size: 10,
      },
      tableData: [],
      total: 1,
      options: this.$store.state.portlist,
      optionsTwo: [
        {
          label: "启用",
          value: "0",
        },
        {
          label: "禁用",
          value: "1",
        },
      ],
    };
  },
  activated() {
    let form = this.form;
    this.postAdminUserCompetencelisttop(form);
  },
  activated() {
    let form = this.form;
    this.postAdminUserCompetencelisttop(form);
  },
  methods: {
    // 查看
    // onLook(id) {
    //   this.$router.push({ name: "SettingModelDetail", query: { id } });
    // },
    // 新增模块
    onAddModel() {
      this.$router.push({ name: "SettingModelOneDetail" });
    },
    // 删除
    onDelete(id) {
      let obj = {
        id,
      };
      this.$confirm("确定删除该模块?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          postAdminUserDelcompetence(obj).then((res) => {
            let form = this.form;
            this.postAdminUserCompetencelisttop(form);
            this.$message({
              type: "success",
              message: "删除成功!",
            });
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    // 编辑
    onEdit(id) {
      this.$router.push({ name: "SettingModelOneDetail", query: { id } });
    },
    // qc列表
    async postAdminUserCompetencelisttop(data) {
      this.loading = true;
      this.form = data;
      let form = JSON.parse(JSON.stringify(this.form));
      // if (form.qc_time) {
      //   form.qc_time = `${form.qc_time[0]}/${form.qc_time[1]}`;
      // }
      postAdminUserCompetencelisttop(form)
        .then((res) => {
          this.loading = false;
          console.log("qc列表", res);
          this.tableData = res.data;
          this.total = Number(res.total);
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    // 搜索
    onSearch() {
      this.form.page = 1;
      this.form.size = 10;
      this.postAdminUserCompetencelisttop(this.form);
    },
  },
};
</script>

<style lang="scss" scoped>
.myform {
  display: flex;
  justify-content: space-between;
  > div {
    display: flex;
  }
  &-item {
    margin-right: 10px;
  }
}
.WorkingSchedule {
  background: #ffff;
  padding: 20px;
  border-radius: 2px;
  @include boxShadow;
}
</style>
